package com.xxxx.server.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxxx.server.mapper.PositionMapper;
import com.xxxx.server.pojo.Position;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.service.IPositionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Date;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhoubin
 */
@Service
public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> implements IPositionService {
    @Resource
    private PositionMapper positionMapper;
    @Override
    public List<Position> selectPositionAll() {
        return positionMapper.selectPositionAll();
    }

    @Override
    public RespBean deletePositionByIds(Integer[] ids) {
        if (positionMapper.deletePositionByIds(ids)>0){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");

    }

    @Override
    public RespBean deletePositionById(Integer id) {
        if (positionMapper.deletePositionById(id)>0){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }

    @Override
    public RespBean insertPosition(Position position) {
        if (position.getName()==null||"".equals(position.getName())){
            return RespBean.error("添加失败！");
        }
        position.setCreateDate(LocalDateTime.now());
        if (positionMapper.insertPosition(position)==1){
            return RespBean.success("添加成功！");
        }
        return RespBean.error("添加失败！");
    }

    @Override
    public RespBean updatePosition(Position position) {
        if (position.getName()==null||"".equals(position.getName())){
            return RespBean.error("修改失败！");
        }
        if (positionMapper.updatePosition(position)==1){
            return RespBean.success("修改成功！");
        }
        return RespBean.error("修改失败！");
    }
}
